﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace QQ.InterviewQuestions.SortedMatrix
{
    internal class SortedMatrix
    {
        private int[,] array;

        public SortedMatrix()
        {
            array = new int[3, 3];
            array[0, 0] = 0;
            array[0, 1] = 10;
            array[0, 2] = 20;
            array[1, 0] = 3;
            array[1, 1] = 40;
            array[1, 2] = 50;
            array[2, 0] = 60;
            array[2, 1] = 70;
            array[2, 2] = 80;
        }

        public Point Find(int a)
        {
            int i, j;
            i = 0;
            j = array.GetUpperBound(1);

            while (i <= array.GetUpperBound(0) && j >= 0)
            {
                if (array[i, j] == a)
                {
                    return new Point(i, j);
                }
                else if (a > array[i, j])
                {
                    i++;
                }
                else if (a < array[i, j])
                {
                    j--;
                }
            }
            return new Point(-1, -1);
        }
    }
}
